// pages/home/home.js
import {Home} from 'home-model.js';
var home = new Home();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shade:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getBannerList();
    this.getMenuList();
    this.getGoodsList();
  },
  shade(){
    this.setData({
      shade:false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  },
  getBannerList(){
    home.getBannerList(res =>{
        this.setData({
          bannerArray:res
        })
    })
  },
  getMenuList(){
    home.getMenuList(res =>{
        this.setData({
          menuArray:res
        })
    })
  },
  getGoodsList(){
    home.getGoodsList(res =>{
         this.setData({
           goodsArray:res
         })
    })
  },
  //轮播图跳转
  onProductsItemTap(event){
   
    var type = home.getDataSet(event,'type');
    var value = home.getDataSet(event,'value');
    if(type == 2){
      wx.navigateTo({
        url: '../list/list?id='+value,
      });
    }
    if(type == 3){
      wx.navigateTo({
        url: '../goods/goods?id='+value,
      });
    }
    
  },
  //菜单跳转
  gotoMenu(event){
    var id = home.getDataSet(event,'id');
    var type = home.getDataSet(event,'type');
    var template = home.getDataSet(event,'template');
    var name =  home.getDataSet(event,'subtitle');
    var color =  home.getDataSet(event,'color');
    color=='' ? '#f6f6f7':color;
    wx.navigateTo({
      url: template+'?id='+id+"&name="+name+'&color='+color+'&type='+type,
    });
  },
    //点击商品
    gotoGoods(event){
      var id = home.getDataSet(event,'id');
      wx.navigateTo({
        url: '../goods/goods?id=' + id,
      });
    },
})